home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / xcmd / dxcmds34.sit / Dartmouth XCMD's 3.4.3 / card_11229.txt < prev    next >
Text File  |  1990-04-17  |  17KB  |  634 lines

  1. -- card: 11229 from stack: in.3
  2. -- bmap block id: 11379
  3. -- flags: 4000
  4. -- background id: 8327
  5. -- name: AuxWindow
  6. ----- HyperTalk script -----
  7. on Install
  8.   put ChooseTargetStack() into it
  9.   InstallResource XCMD,AuxWindow,it
  10. end Install
  11.  
  12. on opencard
  13.   set the visible of button "close windows" to false
  14.   hide card field "demo"
  15.   hide btn "OK"
  16.   pass opencard
  17. end opencard
  18.  
  19. on closeCard
  20.   send mouseUp to btn "close windows"
  21. end closeCard
  22.  
  23.  
  24. -- part 5 (field)
  25. -- low flags: 01
  26. -- high flags: 2007
  27. -- rect: left=18 top=32 right=287 bottom=384
  28. -- title width / last selected line: 0
  29. -- icon id / first selected line: 0 / 0
  30. -- text alignment: 0
  31. -- font id: 3
  32. -- text size: 10
  33. -- style flags: 0
  34. -- line height: 13
  35. -- part name: Documentation
  36.  
  37.  
  38. -- part 6 (button)
  39. -- low flags: 00
  40. -- high flags: 8003
  41. -- rect: left=299 top=298 right=320 bottom=438
  42. -- title width / last selected line: 0
  43. -- icon id / first selected line: 0 / 0
  44. -- text alignment: 1
  45. -- font id: 0
  46. -- text size: 12
  47. -- style flags: 0
  48. -- line height: 16
  49. -- part name: Show C Source
  50. ----- HyperTalk script -----
  51. on mouseUp
  52.   get the visible of card field "source"
  53.   set the visible of card field "source" to not it
  54.   if it is false then
  55.     set the name of me to "Hide C Source"
  56.   else
  57.     set the name of me to "Show C Source"
  58.   end if
  59. end mouseUp
  60.  
  61.  
  62.  
  63. -- part 9 (button)
  64. -- low flags: 00
  65. -- high flags: 0000
  66. -- rect: left=394 top=38 right=132 bottom=484
  67. -- title width / last selected line: 0
  68. -- icon id / first selected line: 0 / 0
  69. -- text alignment: 1
  70. -- font id: 0
  71. -- text size: 12
  72. -- style flags: 0
  73. -- line height: 16
  74. -- part name: Copy This 
  75. ----- HyperTalk script -----
  76. on mouseUp
  77.   global window1,window2,gMemOK
  78.   choose select tool  -- just to see if we have enough memory
  79.   if window1 is empty then
  80.     put "150,140,250,240" into aRect
  81.     set the cursor to watch
  82.     auxWindow "open","aux 1",aRect
  83.     put the result into window1
  84.     put the rect of button 2 into aRect
  85.     auxWindow "use",window1,arect
  86.     if window2 is not empty then
  87.       set the visible of card button swap to true
  88.     end if
  89.   else
  90.     answer "It's window is already up!"
  91.     choose browse tool
  92.   end if
  93.   set the visible of button "close windows" to true
  94. end mouseUp
  95.  
  96.  
  97.  
  98. -- part 10 (button)
  99. -- low flags: 00
  100. -- high flags: 0000
  101. -- rect: left=395 top=141 right=240 bottom=485
  102. -- title width / last selected line: 0
  103. -- icon id / first selected line: 0 / 0
  104. -- text alignment: 1
  105. -- font id: 0
  106. -- text size: 12
  107. -- style flags: 0
  108. -- line height: 16
  109. -- part name: This Too!
  110. ----- HyperTalk script -----
  111. on mouseUp
  112.   global window2,window1
  113.   choose select tool  -- just to see if we have enough memory
  114.   if window2 is empty then
  115.     put "300,140,400,240" into aRect
  116.     set the cursor to watch
  117.     auxWindow "open","aux 2",aRect
  118.     put the result into window2
  119.     put the rect of button 3 into aRect
  120.     auxWindow "use",window2,arect
  121.     if window1 is not empty then
  122.       set the visible of card button swap to true
  123.     end if
  124.   else
  125.     answer "It's window is already up!"
  126.     choose browse tool
  127.   end if
  128.   set the visible of button "close windows" to true
  129. end mouseUp
  130.  
  131.  
  132.  
  133. -- part 16 (button)
  134. -- low flags: 00
  135. -- high flags: A003
  136. -- rect: left=59 top=299 right=322 bottom=202
  137. -- title width / last selected line: 0
  138. -- icon id / first selected line: 0 / 0
  139. -- text alignment: 1
  140. -- font id: 0
  141. -- text size: 12
  142. -- style flags: 0
  143. -- line height: 16
  144. -- part name: Show Windows
  145. ----- HyperTalk script -----
  146. on mouseUp
  147.   show card field "demo"
  148.   show button "OK"
  149. end mouseUp
  150.  
  151.  
  152.  
  153. -- part 11 (button)
  154. -- low flags: 80
  155. -- high flags: 8003
  156. -- rect: left=59 top=299 right=322 bottom=204
  157. -- title width / last selected line: 0
  158. -- icon id / first selected line: 0 / 0
  159. -- text alignment: 1
  160. -- font id: 0
  161. -- text size: 12
  162. -- style flags: 0
  163. -- line height: 16
  164. -- part name: Close Windows
  165. ----- HyperTalk script -----
  166. on mouseUp
  167.   global window1,window2
  168.   if window1 is not empty then
  169.     AuxWindow "close",window1
  170.     put empty into window1
  171.   end if
  172.   if window2 is not empty then
  173.     AuxWindow "close",window2
  174.     put empty into window2
  175.   end if
  176.   set the visible of me to false
  177.   set the visible of button "swap" to false
  178. end mouseUp
  179.  
  180.  
  181.  
  182. -- part 12 (button)
  183. -- low flags: 80
  184. -- high flags: 8003
  185. -- rect: left=402 top=254 right=275 bottom=478
  186. -- title width / last selected line: 0
  187. -- icon id / first selected line: 0 / 0
  188. -- text alignment: 1
  189. -- font id: 0
  190. -- text size: 12
  191. -- style flags: 0
  192. -- line height: 16
  193. -- part name: Swap
  194. ----- HyperTalk script -----
  195. on mouseUp
  196.   global window1,window2
  197.   if window1 is not empty and window2 is not empty then
  198.     set the cursor to watch
  199.     auxwindow "use",window1,the rect of button 3
  200.     auxwindow "use",window2,the rect of button 2
  201.     set the visible of button "swap" to false
  202.   else
  203.     put "You need both windows up to do this."
  204.   end if
  205. end mouseUp
  206.  
  207.  
  208.  
  209. -- part 7 (field)
  210. -- low flags: 81
  211. -- high flags: 0007
  212. -- rect: left=18 top=31 right=292 bottom=488
  213. -- title width / last selected line: 0
  214. -- icon id / first selected line: 0 / 0
  215. -- text alignment: 0
  216. -- font id: 3
  217. -- text size: 10
  218. -- style flags: 0
  219. -- line height: 13
  220. -- part name: Source
  221.  
  222.  
  223. -- part 14 (field)
  224. -- low flags: 81
  225. -- high flags: 0004
  226. -- rect: left=18 top=32 right=226 bottom=368
  227. -- title width / last selected line: 0
  228. -- icon id / first selected line: 0 / 0
  229. -- text alignment: 1
  230. -- font id: 0
  231. -- text size: 12
  232. -- style flags: 0
  233. -- line height: 16
  234. -- part name: demo
  235.  
  236.  
  237. -- part 15 (button)
  238. -- low flags: 80
  239. -- high flags: 8003
  240. -- rect: left=302 top=196 right=218 bottom=357
  241. -- title width / last selected line: 0
  242. -- icon id / first selected line: 0 / 0
  243. -- text alignment: 1
  244. -- font id: 0
  245. -- text size: 12
  246. -- style flags: 0
  247. -- line height: 16
  248. -- part name: OK
  249. ----- HyperTalk script -----
  250. on mouseUp
  251.   hide me
  252.   hide card field "demo"
  253. end mouseUp
  254.  
  255.  
  256.  
  257. -- part contents for card part 5
  258. ----- text -----
  259. AuxWindow Version 1.0d3
  260. Roger Brown
  261.  
  262. AuxWindow is an XCMD that lets you create a new window that is relatively smart in the HyperCard environment. This XCMD does not do anything especially useful, but can serve as a shell for more elaborate operations. As presented here, AuxWindow lets you create any number of auxiliary windows. For each, you specify a name and a frame rectangle. The window created is of type rDocProc with no go-away box. This is important, because a window needs to be disposed using the XCMD "close" operation so that the window pointer is properly purged. 
  263.  
  264. An auxiliary window can be dragged around and put in front or behind other windows such as the tools and pattern palettes, desk accessories, and other auxiliary windows. The card window will always stay behind, of course.  HyperCard is very smart about managing windows. An auxiliary window will properly update its contents because they are stored as a WindowPicture. (See the LSC code.) One oddity is that you must click on the title bar to activate one of them. This is HyperCard's doing.
  265.  
  266. The XCMD as presented here allows you to open a window and later close it. The script must maintain the window pointer in a global. For HyperCard versions later than 1.1 this business could be hidden in a global that never appears in a script.  To do this, you can manage the window pointer in a global accessed from the XCMD using the GetGlobal and SetGlobal call back routines.  Use a global name that is unlikely to be used in a script for other purposes, so that it is only known by the XCMD.   If you do this, you do not need to pass the window pointer value in and out of the XCMD.  If you have more than one auxiliary window open at a time, however, you will need some parameter to identify which window each call to the XCMD is intended for.
  267.  
  268. With this version, you can also use a window to hold a drawing. The code calls back to HyperCard to copy a area of the card's paint layer and installs the copy in the aux window using the clipboard. (See the LSC code.) This version supports color windows, but a copy from HyperCard is not likely to be in color! (The current version of HyperCard at the time of his release is 1.2.2).
  269.  
  270. To try it, click on the patterns marked "Copy This!" and "This Too!" on the right side of this card. The patterns you click on will appear in auxiliary windows. Then move them around a bit with other windows present to see what happens. Press the "Swap" button to see the pictures interchange.   Finally, close the windows by pressing the "Close" button. Look at the scripts of these buttons to see how to use the XCMD.
  271.  
  272. INVOKING AuxWindow
  273.  
  274.    AuxWindow "open",name of window, frame rect of window
  275.        the result must be held in a global, this is the Window Pointer
  276.  
  277.    AuxWindow "use",window pointer global, rectangle to copy
  278.  
  279.    AuxWindow "close", window pointer
  280.  
  281.  
  282. REVISION HISTORY
  283. 1.0d1 7/1/88 add name and frame parameters
  284. 1.0d2 7/15/88 add color window support
  285. 1.0d3 3/10/89 update for LightSpeed C version 3.0
  286.  
  287.  
  288. -- part contents for card part 7
  289. ----- text -----
  290. /* AuxWindow1.0d3.c */
  291. /* ┬⌐ Trustees of Dartmouth College */
  292. /* written in LightSpeed C  ┬⌐ Think Technologies, Inc */
  293. /* Roger Brown, Dartmouth Courseware Development Group 3/10/89 */
  294. /* version 1.0d3 update for LSC 3.0 */
  295. /* version 1.0d2 add color window support */
  296. /* version 1.0d1 add name and location rect in open */
  297.  
  298. /* Creates a floating no go-away window with a picture that is cut
  299.    from a card.
  300.    
  301.     syntax is:
  302.                 AuxWindow "open",name,rectangle of window
  303.                     returns window pointer
  304.                     
  305.                 AuxWindow "use",window pointer,rectangle to copy
  306.                 
  307.                 AuxWindow "close",window pointer
  308.                 
  309. */
  310.  
  311. #include "stddata_ctype.c"
  312. #include "QuickDraw.h"
  313. #include "WindowMgr.h"
  314. #include "MemoryMgr.h"
  315. #include "ToolboxUtil.h"
  316. #include "strings.c"
  317. #include "HyperXCmd.h"
  318. #include "XCmdGlue.inc.c"
  319. #include "SetUpA4.h"
  320.  
  321. #define FALSE 0
  322. #define TRUE 1
  323. #define HORIZ 1
  324. #define VERT  2
  325. #define VISIBLE 1
  326.  
  327. /* globals */
  328.  
  329. XCmdBlockPtr    gParamPtr;
  330.  
  331. WindowPtr theWindow;    
  332. PicHandle itsPic;
  333.  
  334. Str255 theResult;
  335. Rect windowRect,grabRect;
  336.  
  337. /* return the max of two ints */
  338.  
  339. max(a,b)
  340. int a,b;
  341. {   
  342.     if (a>b) return a;
  343.     return b;
  344. }
  345.  
  346. /* convert a character to upper case */
  347.  
  348. int toupper(c)
  349. char    c;
  350. {
  351.     return( (c>='a')&&(c<='z') ? (c-('a'-'A')) : c );
  352. }
  353.  
  354. /* convert a string to upper case */
  355.  
  356. ucase(s)
  357. char *s;
  358. {
  359.     int i,l;
  360.     l = strlen(s);
  361.     for (i=0;i<l;i++) s[i] = toupper(s[i]);
  362. }
  363.  
  364. /* get a HyperCard item as a numeric value */
  365.  
  366. int GetHCNumberItem(s,i)
  367. char *s;
  368. int i;
  369. /* Get HyperCard comma delimited item i from item list string s. */
  370. {
  371.     int c,len,count,j;
  372.     char temp[32];
  373.     long it;
  374.     
  375.     count = j = 0;
  376.     len = strlen(s);
  377.     for (c=0;c<len;c++) {
  378.         if (s[c]==',') {
  379.             count = count + 1;
  380.             if (count==i) break;
  381.             j = 0;
  382.         }
  383.         else {
  384.             temp[j] = s[c];
  385.             j++;
  386.             if (c==(len-1)) { /* last item, no comma */
  387.                 count = count+1;
  388.                 break;
  389.             }
  390.         }
  391.     }
  392.     if (count < i) strcpy(temp,"");  /* no item there */
  393.     temp[j] = 0;
  394.     CtoPstr(temp);
  395.     StringToNum(temp,&it);
  396.     return (int)it;
  397. }
  398.  
  399.  
  400. /* copy the current card in the given rectangle and make it into a picture */
  401.  
  402. GetMyPicture()
  403. {
  404.     Str255 buildStr;
  405.     char temp[32];
  406.     long len,offset;
  407.  
  408.     strcpy(buildStr,"set lockscreen to true");
  409.     CtoPstr((char *)buildStr);
  410.     SendCardMessage(gParamPtr,buildStr);
  411.     
  412.     strcpy(buildStr,"choose select tool");
  413.     CtoPstr((char *)buildStr);
  414.     SendCardMessage(gParamPtr,buildStr);
  415.     
  416.     strcpy(buildStr,"drag from ");
  417.     NumToString((long)grabRect.left,temp);
  418.     PtoCstr((char *)temp);
  419.     strcat(buildStr,temp);
  420.     strcat(buildStr,",");
  421.     NumToString((long)grabRect.top,temp);
  422.     PtoCstr((char *)temp);
  423.     strcat(buildStr,temp);
  424.     strcat(buildStr," to ");
  425.     NumToString((long)grabRect.right,temp);
  426.     PtoCstr((char *)temp);
  427.     strcat(buildStr,temp);
  428.     strcat(buildStr,",");
  429.     NumToString((long)grabRect.bottom,temp);
  430.     PtoCstr((char *)temp);
  431.     strcat(buildStr,temp);
  432.     CtoPstr((char *)buildStr);
  433.     SendCardMessage(gParamPtr,buildStr);
  434.     
  435.     strcpy(buildStr,"domenu copy picture");
  436.     CtoPstr((char *)buildStr);
  437.     SendCardMessage(gParamPtr,buildStr);
  438.         
  439.     strcpy(buildStr,"choose browse tool");
  440.     CtoPstr((char *)buildStr);
  441.     SendCardMessage(gParamPtr,buildStr);
  442.     
  443.     
  444.     strcpy(buildStr,"set lockscreen to false");
  445.     CtoPstr((char *)buildStr);
  446.     SendCardMessage(gParamPtr,buildStr);
  447.     
  448.     itsPic = (PicHandle)NewHandle(0);
  449.     len = GetScrap((PicHandle)itsPic,'PICT',&offset);
  450.  
  451. }
  452.  
  453. /* see if window can be a color window */
  454.  
  455. ColorQDExists()
  456. {
  457.         typedef struct SysEnvRec {
  458.                 short   environsVersion;
  459.                 short   machineType;
  460.                 short   systemVersion;
  461.                 short   processor;
  462.                 Boolean hasFPU;
  463.                 Boolean hasColorQD;
  464.                 short   keyBoardType;
  465.                 short   atDrvrVersNum;
  466.                 short   sysVRefNum;
  467.         } SysEnvRec;
  468.  
  469.         SysEnvRec theWorld;
  470.         OSErr err;
  471.         
  472.         err = SysEnvirons(1,&theWorld);
  473.         if (err!=noErr) return 0;
  474.         return (int)theWorld.hasColorQD;
  475. }
  476.  
  477. /* create a window on the fly */
  478.  
  479. CreateWindow(name,frame)
  480. char *name;
  481. Rect *frame;
  482. {
  483.     CtoPstr((char *)name);
  484.     if (ColorQDExists()) 
  485.         theWindow = (WindowPtr)NewCWindow(NULL,frame,name,TRUE,rDocProc,
  486.                 (WindowPtr)-1,FALSE,NULL);
  487.     else theWindow = NewWindow(NULL,frame,name,TRUE,rDocProc,
  488.                 (WindowPtr)-1,FALSE,NULL);
  489. }
  490.  
  491. /* open a window */
  492.  
  493. OpenWindow()
  494. {
  495.     Ptr theRect,theName;
  496.     char theRectStr[32];
  497.     Str255 theNameStr;
  498.     GrafPtr gp;
  499.     Rect windowRect;
  500.         
  501.     theName = *(gParamPtr->params[1]);
  502.     strcpy(theNameStr,theName);
  503.     theRect = *(gParamPtr->params[2]);
  504.     strcpy(theRectStr,theRect);
  505.     
  506.     windowRect.left = GetHCNumberItem(theRectStr,1);
  507.     windowRect.top = GetHCNumberItem(theRectStr,2);
  508.     windowRect.right = GetHCNumberItem(theRectStr,3);
  509.     windowRect.bottom = GetHCNumberItem(theRectStr,4);
  510.     
  511.     CreateWindow(theNameStr,&windowRect);
  512.     NumToString(theWindow,theResult);
  513.     PtoCstr((char *)theResult);     
  514.     ShowWindow(theWindow);
  515.     BringToFront(theWindow);
  516. }
  517.  
  518. /* use the window to present the copied picture */
  519.  
  520. UseWindow()
  521. {
  522.     Ptr theWindowPtr;
  523.     Ptr theRect;
  524.     Rect badRect;
  525.     Str255 wPointer;
  526.     char message[32],theRectStr[32];
  527.     GrafPtr gp;
  528.     
  529.     theWindowPtr = *(gParamPtr->params[1]);
  530.     strcpy(wPointer,theWindowPtr);
  531.     CtoPstr((char *)wPointer);
  532.     StringToNum(wPointer,&theWindow);
  533.     theRect = *(gParamPtr->params[2]);
  534.     strcpy(theRectStr,theRect);
  535.     
  536.     grabRect.left = GetHCNumberItem(theRectStr,1);
  537.     grabRect.top = GetHCNumberItem(theRectStr,2);
  538.     grabRect.right = GetHCNumberItem(theRectStr,3);
  539.     grabRect.bottom = GetHCNumberItem(theRectStr,4);
  540.  
  541.     
  542.     itsPic = GetWindowPic(theWindow);
  543.     if (itsPic != 0L) KillPicture(itsPic);
  544.     GetMyPicture();
  545.     if (GetHandleSize(itsPic) > 0L ) {
  546.         SetWindowPic(theWindow,itsPic);
  547.         GetPort(&gp);
  548.         SetPort(theWindow);
  549.         SetOrigin(grabRect.left,grabRect.top);
  550.         SetPort(theWindow);
  551.         badRect = (*theWindow).portRect;
  552.         InvalRect(&badRect);
  553.         SetPort(gp);
  554.         BringToFront(theWindow);
  555.     }
  556.     NumToString(theWindow,theResult);
  557.     PtoCstr((char *)theResult);     
  558. }
  559.  
  560. /* close the window */
  561.  
  562. CloseWindow()
  563. {
  564.     Ptr theWindowPtr;
  565.     Str255 wPointer;
  566.     
  567.     theWindowPtr = *(gParamPtr->params[1]);
  568.     strcpy(wPointer,theWindowPtr);
  569.     CtoPstr((char *)wPointer);
  570.     StringToNum(wPointer,&theWindow);
  571.     
  572.     itsPic = GetWindowPic(theWindow);
  573.     if (itsPic != 0L) KillPicture(itsPic);
  574.     DisposeWindow(theWindow);
  575.     strcpy(theResult,"0");
  576. }
  577.  
  578. /* branch on the opcode given in param[0] */
  579.  
  580. AuxWindow()
  581. {   
  582.     Ptr theMessage;
  583.     char message[32];
  584.     
  585.     theMessage = *(gParamPtr->params[0]);
  586.     strcpy(message,theMessage);
  587.     ucase(message);
  588.         
  589.     if (strcmp(message,"OPEN")==0) OpenWindow();
  590.     else if (strcmp(message,"USE")==0) UseWindow();
  591.     else if (strcmp(message,"CLOSE")==0) CloseWindow();
  592.     else {        /* undefined message */
  593.         SysBeep(0);
  594.         strcpy(theResult,"Undefined message in auxwindow XCMD");
  595.     }   
  596. }
  597.  
  598. /* XCMD enty point */
  599.  
  600. pascal void main(paramPtr)
  601. XCmdBlockPtr    paramPtr;
  602. {
  603.     long len;
  604.     Handle resultHandle;
  605.     
  606.     RememberA0();
  607.     SetUpA4();                          /* to use global variables */
  608.     gParamPtr = paramPtr;
  609.     AuxWindow();                        /* run the XCMD */
  610.     
  611.     /* return the result */
  612.     len = 1+strlen(theResult);
  613.     resultHandle = NewHandle(len);
  614.     HLock(resultHandle);
  615.     BlockMove(theResult,*resultHandle,len);
  616.     HUnlock(resultHandle);
  617.     paramPtr->returnValue = resultHandle;
  618.     
  619.     /* all done */
  620.     RestoreA4();       
  621.     return;
  622. }
  623.  
  624.  
  625. -- part contents for card part 14
  626. ----- text -----
  627.  
  628. Click on the panel labelled "Copy This!".
  629. The click on the panel labelled "This Too!"
  630. Then push the "Swap" button.  Then 
  631. drag the windows around some.
  632.  
  633. If you get a warning that there is not enough memory to use the paint tools, the demo will not work.  To fix it, quit HyperCard and start this stack up again.  Go directly to this card by choosing 
  634. "AuxWindow" from the index.